﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace K.EnterpriseLibary
{
    public static class AddonPublic
    {
        public const string AddonIDResourceName = "AddonID";
        public const string AddonNameResourceName = "AddonName";
        public const string AddonCategoryResourceName = "AddonCategory";
        public const string AddonDescriptionResourceName = "AddonDescription";

        private static string GetResourceString(Type addonType, string resourceName)
        {
            return addonType.GetResourceString(resourceName);
        }

        public static List<TAddonInfo> FindAddonInfoList<TAddonInfo>(Predicate<AddonInfo> findMethod)
            where TAddonInfo : AddonInfo, new()
        {
            System.Diagnostics.Debug.Assert(findMethod != null);

            /// 獲取某個基類的所有子類的Addon信息
            IEnumerable<Type> addonTypes = ReflectionPublic.FindAddonTypes(
                p =>
                {
                    return findMethod(p);
                });
            List<TAddonInfo> addonInfoList = new List<TAddonInfo>();
            foreach (Type addonType in addonTypes)
            {
                TAddonInfo addonInfo = new TAddonInfo();
                addonInfo.Type = addonType;
                if (addonInfo != null && !addonInfoList.Contains(addonInfo))
                {
                    addonInfoList.Add(addonInfo);
                }
            }
            return addonInfoList;
        }
    }
}
